package org.tsinghua.vaccine.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tsinghua.core.ResultMapper;
import org.tsinghua.vaccine.controller.vo.CirculationVo;
import org.tsinghua.vaccine.controller.vo.InoculationVo;
import org.tsinghua.vaccine.entity.Circulation;
import org.tsinghua.vaccine.entity.Inoculation;
import org.tsinghua.vaccine.entity.Vaccine;
import org.tsinghua.vaccine.service.VaccineService;

import java.util.Map;

/**
 * @author ipenta
 * @ClassName: VaccineTrackingController
 * @Description: TODO
 * @date 2017-09-20 上午9:00
 */
@Api(description = "疫苗流通/接种交易信息存储")
@RestController
@RequestMapping("/api/v1/tx")
public class VaccineTransactionController {


	@Autowired
	VaccineService vaccineService;




	@ApiOperation(value = "存储接口：疫苗流通", notes = "用于存储疫苗【交易】信息", produces = "application/json")
	@PostMapping("/vaccine")
	@ResponseBody
	public Map<String, Object> vaccine(@RequestBody final CirculationVo circulationVo) {

		Vaccine vaccine = new Vaccine(circulationVo.getVaccineId(),circulationVo.getVaccineCode(),circulationVo.getVaccineComp(),circulationVo.getVaccineBatchCode(),circulationVo.getVaccineBoxNo(),circulationVo.getVaccinePkgNo());
		Circulation circulation = new Circulation(circulationVo.getOrderNo(),circulationVo.getOrderType(),circulationVo.getOrderDate(),circulationVo.getSupplyOrganCode(),circulationVo.getReceiveOrganCode());

		return ResultMapper.success(vaccineService.recordCirculation(vaccine,circulation));
	}

	@ApiOperation(value = "存储接口：疫苗接种", notes = "用于存储疫苗【接种】信息", produces = "application/json")
	@PostMapping("/inoculation")
	@ResponseBody
	public Map<String, Object> inoculation(@RequestBody final InoculationVo inoculationVo) {

		Inoculation inoculation = new Inoculation(inoculationVo.getOrderNo(),inoculationVo.getOrderType(),inoculationVo.getOrderDate(),inoculationVo.getRecodeOrganCode(),inoculationVo.getRecodeOperCode(),inoculationVo.getChildCode(),inoculationVo.getScrapFlag());

		return ResultMapper.success(vaccineService.recordInoculation(inoculationVo.getVaccineId(),inoculation));

	}
}
